module.exports = async function bill(query) {
    const res = await query(`SHOW TABLES LIKE 'billList'`)
    //  如果没有表就创建表
    if (!res || res.length === 0) {
        await query(`
            create table billList(
                id int not null auto_increment,
                name varchar(20) not null,
                userid varchar(20) not null,
                price int(20) not null,
                spend BOOLEAN not null,
                type varchar(20) not null,
                date varchar(20) not null,
                primary key(id)
            )
        `, err => {
            if (err) console.log(err);
        })
    }

    /* 模拟数据 */
    // mockData() // 模拟数据
    function mockData() {
        for (let i = 0; i <= 100; i++) {
            let data = {
                name: `cxl${i}`,
                userid: `cxlid${i}`,
                price: i,
                spend: i % 2 === 0 ? true : false,
                type: i % 2 === 0 ? 'eat' : 'buy',
                date: new Date().getTime()
            }
            // console.log(data);
            const sql = `insert into billList (name,price,spend,type,date,userid) values('${data.name}',${data.price},${data.spend},'${data.type}',${data.date},'${data.userid}')`
            query(sql)
        }
    }
}